﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Com.CMS263.Util
{
    
    public class ValidateUtil
    {
        /// <summary>
        /// 验证手机号码
        /// </summary>
        /// <param name="strNumber"></param>
        /// <returns></returns>
        public bool IsMobile(String strNumber)   //验证手机号码
        {
            Regex objNotIntPattern = new Regex("(13|15|18)([0-9]*)");
            return objNotIntPattern.IsMatch(strNumber);
        }
        /// <summary>
        /// 验证是否是电话号码
        /// </summary>
        /// <param name="strIn"></param>
        /// <returns></returns>
        public bool isTel(string strIn)
        {
            return Regex.IsMatch(strIn, @"(d+-)?(d{4}-?d{7}|d{3}-?d{8}|^d{7,8})(-d+)?");
        }

        public bool chkDate(string str)
        {

            if (string.IsNullOrEmpty(str))
            {
                str = "";
            }

            str = str.Trim();
            try
            {
                DateTime t1 = DateTime.Parse(str);
                return true;
            }
            catch
            {
                return false;
            }
        }
        /// <summary>
        /// 验证是否是数字
        /// </summary>
        /// <param name="str">传递过来的字符串</param>
        /// <returns></returns>
        public bool IsNumeric(string str)
        {
            if (str == null || str.Length == 0)
                return false;
            foreach (char c in str)
            {
                if (!Char.IsNumber(c))
                {
                    return false;
                }
            }
            return true;
        }
        /// <summary>
        /// 验证邮箱合法性
        /// </summary>
        /// <param name="inputEmail"></param>
        /// <returns></returns>
        public static bool isEmail(string inputEmail)
        {
            string strRegex = @"^([a-zA-Z0-9_-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([a-zA-Z0-9-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$";
            Regex re = new Regex(strRegex);
            if (re.IsMatch(inputEmail))
                return (true);
            else
                return (false);
        }
        /// <summary>
        /// 判断是否是浮点数
        /// </summary>
        /// <param name="inputDouble"></param>
        /// <returns></returns>
        public static bool isDouble(string inputDouble)
        {
            string strRegex = "^(-?\\d+)(\\.\\d+)?$";
            Regex re = new Regex(strRegex);
            if (re.IsMatch(inputDouble))
                return (true);
            else
                return (false);
        }
        /// <summary>
        /// 判断是否是正浮点数
        /// </summary>
        /// <param name="inputDouble"></param>
        /// <returns></returns>
        public static bool isDou(string inputDouble)
        {
            string strRegex = "^(\\d+)(\\.\\d+)?$";
            Regex re = new Regex(strRegex);
            if (re.IsMatch(inputDouble))
                return (true);
            else
                return (false);
        }



    }
}
